import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Input, Select, Button } from 'antd';
import Home_table from './Home_table';
import Home_add from './Home_add';
import action from '../../store/action';
import { explan } from '../view_public/Add_public';
import { onkeyDown } from '../../store/function';

class index extends React.Component {
    constructor() {
        super();
        this.state = {
            input_value: ''
        }
    }
    async componentWillMount() {
        setTimeout(() => {
            if (!sessionStorage.getItem('admin_key')) {
                this.props.history.push('/sign')
            }
        })
    }
    render() {
        const { Option } = Select;
        const { Search } = Input;
        return <div>
            <div>
                {
                    explan('说明：单位管理是管理员建立各单位基本信息')
                }
            </div>
            <div className="search_div">
                标题:
                <Search placeholder="请输入关键字" className="search_input" onChange={(e) => this.handleChange(e)} onKeyUp={(e)=>onkeyDown(e,this.handel_search)}></Search>
                <Button type="primary" className='search_btn' style={{ background: '#FB6137', borderColor: '#FB6137' }} onClick={this.handel_search}>搜索</Button>

            </div>
            <div>
                <Home_add />
                <Home_table />
            </div>
        </div>
    }
    handleChange = (e) => {
        this.setState({
            input_value: e.target.value
        })
    }
    
    handel_search = () => {
        const val = this.state.input_value;
        this.$axios.get(`/manager/api/getAllOrganizationList?name=${val}`).then((res) => {
            const {home_search}=this.props;
            home_search(res.organizationList)
        }).catch((err) => {
            console.log(err);
        })
    }
}

export default connect(state=>({...state.custom}),action.custom)(index);